package pers.qianyu.month_202011.date_20201118;

import java.util.*;

/**
 * 1. 两数之和
 * https://leetcode-cn.com/problems/two-sum/
 *
 * @author mizzle rain
 * @date 2020-11-18 15:29
 */
public class TwoSum {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int a = target - nums[i];
            if (map.containsKey(a) && map.get(a) != i) {
                return new int[]{i, map.get(a)};
            }
            map.put(nums[i], i);
        }
        return null;
    }

    public static void main(String[] args) {
        int[] result = new TwoSum().twoSum(new int[]{3, 3}, 6);
        System.out.println("result = " + Arrays.toString(result));
    }
}
